
public class Animation
{

  public OBJModel model [];
  public int currentFrame = 0;
  public int frames = 0;
  public String directory = "";
  public Action action = Action.Repeat;

  public OBJModel getFrame()
  {
    return model[currentFrame];
  }

  public Animation(PApplet var, String directory)
  {

    this.directory = directory;
    LoadFrames(var);
  }

  public void LoadFrames(PApplet var)
  {
    String path = sketchPath + "/" + directory;
    String[] filenames = new File(path).list();

    if (filenames == null)
      println("ERROR");
    else
    {
      frames = filenames.length;
      model = new OBJModel[frames];
      // making an object called "model" that is a new instance of OBJModel
      for (int x = 0; x < frames;x++)
      {
        model[x] = new OBJModel(var, "s/exp_"+x+".obj", "relative", POLYGON);
        model[x].enableDebug();
        model[x].scale(8);
      }
    }
  }

  public void Draw()
  {

    if (currentFrame>=frames && action == Action.Repeat)
      currentFrame = 0;
    if (currentFrame<frames)
      model[currentFrame++].draw();
    else
      model[0].draw();
  }
}

